** See the Readme.txt file for additional instructions about downloading raw data.

* Start by setting the COMPDRIVE filepath to the folder where your analysis will be held
* This do file will prepare all of the raw data for analysis then run the demand system estimation. 
* You can specify estimation options in the Estimation_3sls.do file 
* You can set the number of bootstrap iterations for computing standard errors in teh Estimation_3sls_bootstrap.do file
* The postest do file computes elasticities and makes summary figures and tables. The compfigs allows for comparison of elasticities between multiple specifications. The specifications need to be created before a comparision is possible, and the user should list the two specifications in the compfigs do file. 



clear
set max_memory 15g, permanently
set matsize 10000

gl COMPDRIVE "Y:\1_Publish\VillageEconomies"  
gl LOCDRIVE 	"${COMPDRIVE}\Replication"
gl DATADRIVE 	"${COMPDRIVE}\Replication\Raw"

gl AUX 	"${LOCDRIVE}\Ado"

sysdir set PERSONAL $AUX
set scheme solcolor

gl DATA = 0 /*Set to 1 if doing data prep*/
gl ANAL = 1 /*Set to 1 if doing demand estimation*/


***************
** Data Prep **
***************

if ${DATA} == 1	{
	gl YEARLIST	2008-09_R1 2010-11_R2 2012-13_R3

	do "${LOCDRIVE}\Parameters.do"	 

	foreach yr of global YEARLIST	{
		parse "`yr'", parse("_")
		gl YEAR "`1'"
		gl ROUND `3'
	
		do "${LOCDRIVE}\DataPrep_Tanzania_${YEAR}.do"
		}	

	do "${LOCDRIVE}\PanelAssembly.do"
	do "${LOCDRIVE}\PanelPrices.do"
	}


**************
** Analysis **
**************

if ${ANAL} == 1	{
	do "${LOCDRIVE}\Parameters.do"

	** Estimate EASI model (specify which goods need instruments within estimation do file)
	do "${LOCDRIVE}\Estimation_3sls.do" 
	
	** Bootstrap standard errors for the coefficients estimated above (set the number of iterations in the do file)
	do "${LOCDRIVE}\Estimation_3sls_bootstrap.do" 

	** Post-estimation parameter recovery, elasticity calculation, and results visualization (specify which estimation results to load in the do file)
	do "${LOCDRIVE}\Estimation_3sls_postest.do"
	
	** Create figures to compare elasticities across specifications
	do "${LOCDRIVE}\Estimation_3sls_compfigs.do"	
	}
